<template>
  <el-tree
    :props="defaultProps"
    :load="loadNode"
    lazy
    :expand-on-click-node="false"
    :highlight-current="true"
    :check-on-click-node="true"
    @node-click="handleNodeClick"
  />
</template>

<script setup>
import { ref, reactive } from 'vue'
import { get_org_tree2, get_org_tree3 } from '@/api/system.js'
import { stringify } from 'qs'
const props = defineProps({
  value: {
    type: String
  },
  url: {
    type: String,
    default: ''
  }
})
const defaultProps = {
  label: 'orgName'
}
let form = ref()
const getList = async params => {
  let res =
    props.url === 'getOrgTree3' //资产产权信息查询机构树
      ? await get_org_tree3(params)
      : await get_org_tree2(params)
  if (res.succeed) {
    return res.data
  }
}
const loadNode = async (node, resolve) => {
  if (node.level === 0) {
    return resolve(await getList())
  }
  let params = {
    orgPid: node.data.id,
    orgType: node.data.orgType,
    isVirtual: node.data.isVirtual
  }
  return resolve(await getList(params))
}
const emit = defineEmits(['update:value', 'select','selectItem'])
const handleNodeClick = data => {
  emit('select', data.id)
  emit('selectItem',data)
}
</script>
<style lang="scss" scoped></style>
